﻿Public Class WageCalc
    Private Sub WageCalc_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        lblHourlyWageOutput.Text = ""
        lblMonthlyWageOutput.Text = ""
        lblAnnualWageOutput.Text = ""
    End Sub

    Private Sub btnAbout_Click(sender As System.Object, e As System.EventArgs) Handles btnAbout.Click
        MessageBox.Show("Copyright 2013 Brendan K Callahan" & ControlChars.CrLf & "Released under Creative Commons Licensing $NO BY SAME", "Thanks for asking...", MessageBoxButtons.OK)
    End Sub


    Private Sub btnCalculate_Click(sender As System.Object, e As System.EventArgs) Handles btnCalculate.Click
        Dim sngCalculatedHourly As Single
        Dim sngCalculatedMonthly As Single
        Dim sngCalculatedAnnual As Single
        Dim sngWageInput As Single

        If Single.TryParse(txtWageTextInput.Text, sngWageInput) Then

            'Calculate from Annual
            If cboWagePeriod.SelectedIndex = 0 Then 'Annual selected - calculate Monthly and Hourly
                If sngWageInput < 0 Then
                    MessageBox.Show("That's not a wage, it's a donation :)", "Seriously?!?", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
                ElseIf sngWageInput = 0 Then
                    MessageBox.Show("Volunteer work, eh?", "You rock!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
                ElseIf sngWageInput > 99998084 Then
                    MessageBox.Show("You're making over $48,076/hr?", "Seriously?!?", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
                Else
                    sngCalculatedHourly = (sngWageInput / 40) / 52
                    sngCalculatedMonthly = sngWageInput / 12
                    lblHourlyWageOutput.Text = sngCalculatedHourly.ToString("c") & " per hour"
                    lblMonthlyWageOutput.Text = sngCalculatedMonthly.ToString("c") & " per month"
                    lblAnnualWageOutput.Text = sngWageInput.ToString("c") & " per year"
                End If
            End If

            'Calculate from Hourly
            If cboWagePeriod.SelectedIndex = 1 Then 'Monthly selected - calculate Annual and Hourly
                If sngWageInput < 0 Then
                    MessageBox.Show("That's not a wage, it's a donation :)", "Seriously?!?", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
                ElseIf sngWageInput = 0 Then
                    MessageBox.Show("Volunteer work, eh?", "You rock!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
                ElseIf sngWageInput > 48076 Then
                    MessageBox.Show("You're making over $99,998,084/yr?", "Seriously?!?", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
                Else
                    sngCalculatedAnnual = sngWageInput * 40 * 52
                    sngCalculatedMonthly = sngCalculatedAnnual / 12
                    lblHourlyWageOutput.Text = sngWageInput.ToString("c") & " per hour"
                    lblMonthlyWageOutput.Text = sngCalculatedMonthly.ToString("c") & " per month"
                    lblAnnualWageOutput.Text = sngCalculatedAnnual.ToString("c") & " per year"
                End If
            End If

            'Calculate from Monthly
            If cboWagePeriod.SelectedIndex = 2 Then 'Annual selected - calculate Monthly and Hourly
                If sngWageInput < 0 Then
                    MessageBox.Show("That's not a wage, it's a donation :)", "Seriously?!?", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
                ElseIf sngWageInput = 0 Then
                    MessageBox.Show("Volunteer work, eh?", "You rock!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
                ElseIf sngWageInput < 1.73 Then
                    MessageBox.Show("Does it really matter if the wage is less than $0.01/hr?", "Seriously?!?", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
                ElseIf sngWageInput > 8333174 Then
                    MessageBox.Show("You're making over $8,333,174/hr?", "Seriously?!?", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
                Else
                    sngCalculatedHourly = ((sngWageInput * 12) / 52) / 40
                    sngCalculatedAnnual = sngWageInput * 12
                    lblHourlyWageOutput.Text = sngCalculatedHourly.ToString("c") & " per hour"
                    lblMonthlyWageOutput.Text = sngWageInput.ToString("c") & " per month"
                    lblAnnualWageOutput.Text = sngCalculatedAnnual.ToString("c") & " per year"
                End If
            End If
        Else
            MessageBox.Show("Please make sure you enter a valid numeric value only." & ControlChars.CrLf & "You should not use a '$' or other currency symbol.", "Woah...", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
        End If
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub
End Class